package Utility;

import java.text.SimpleDateFormat;
import java.util.Date;

import DataBase.Assignment;
import DataBase.AssignmentManager;

public class AsmtHandlerGenerator extends Thread {
//    private Assignment asmt;
	public void run() {
		System.out.println("AsmtHandlerGenerator : run");
		while (true) {
			System.out.println("AsmtHandflerGenerator : GetLatestAsmt");
			Assignment asmt = AssignmentManager.GetLatestAsmt();
			if (asmt == null) {
				System.out.println("asmt : 当前无处于启动状态的任务");
				try {
					Thread.sleep(10000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				continue;
			}
			
			String fulltime = asmt.getfulltime();
			Date nowdate = new Date();
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-ss");
			String now = df.format(nowdate);
			if (now.compareTo(fulltime) < 0) {
				System.out.println("asmt : 当前早于最早执行任务的时间");
				try {
					Thread.sleep(10000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				continue;
			}
			asmt.setAsmt_state("执行中");
		    AssignmentManager.update(asmt);
			Thread assignmenthandler = new Thread(new AssignmentHandler(asmt));
			assignmenthandler.start();
			
			
		}
	}
	
}
